﻿//----设置Cookie------

function setCookie(name, value, domain) {
    var value = escape(value);
    var nameString = "Drag_" + name + "=" + value; //给cookie变量增加前缀 
    var extime = new Date();
    extime.setTime(extime.getTime() + 315360000);
    var expiryString = ";expires=" + extime.toGMTString();
    var domainString = "";
    var pathString = ";path=/";
    var setvalue = nameString + expiryString;
    document.cookie = setvalue;
}

//----设置Cookie 结束------

//---读取Cookie-------

function getcookie(name) {
    var CookieFound = false;
    var start = 0;
    var end = 0;
    var CookieString = document.cookie;
    var i = 0;
    name = "Drag_" + name; //增加前缀
    while (i <= CookieString.length) {
        start = i;
        end = start + name.length;
        if (CookieString.substring(start, end) == name) {
            CookieFound = true;
            break;
        }
        i++;
    }

    if (CookieFound) {
        start = end + 1;
        end = CookieString.indexOf(";", start);
        if (end < start)
            end = CookieString.length;
        var getvalue = CookieString.substring(start, end);
        return unescape(getvalue);
    }
    return "";
}

//---读取Cookie 结束-------

//检测是否禁用了cookie
function isEnableCookie() {
    try {
        var cookie_helper = new CookieHelper("");
        var test_cookie_name = "test_cookie_name";
        var test_cookie_value = "test_cookie_value";
        var test_cookie_value_ret = "";

        cookie_helper.writeCookie(test_cookie_name, test_cookie_value);
        test_cookie_value_ret = cookie_helper.getCookieValue(test_cookie_name);

        if (test_cookie_value_ret != null) {
            cookie_helper.removeCookie(test_cookie_name);
            return true;
        } else {
            return false;
        }
    } catch (error) {
        return false;
    }
} 
